package com.tjvib.util;

import android.annotation.SuppressLint;
import android.content.Context;

import android.os.Looper;
import android.widget.Toast;

import androidx.annotation.StringRes;

import java.util.Timer;
import java.util.TimerTask;

public class ToastUtil {

    private static Toast toast;

    private static Context context;


    public static void init(Context context) {
        ToastUtil.context = context;
    }

    public static void show(String content) {
//        if (toast != null) {
//            toast.cancel();
//        }
//
//        toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
//        toast.show();

        try {
            if (toast != null) {
                toast.setText(content);
            } else {
                toast = Toast.makeText(context, content, Toast.LENGTH_SHORT);
            }
            toast.show();
        } catch (Exception e) {
            Looper.prepare();
            Toast.makeText(context, content, Toast.LENGTH_SHORT).show();
            Looper.loop();
        }
    }

    public static void show(@StringRes int resId) {
        show(context.getString(resId));
    }
}
